package com.sgzn.sgpay.web.bootstrap;

import com.google.common.util.concurrent.AbstractIdleService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @author huangsenguang
 * @version Id: Bootstrap.java, v 0.1 2018/5/19 11:10 huangsenguang Exp $$
 */
public class Bootstrap extends AbstractIdleService {
    private static final Logger LOG = LoggerFactory.getLogger(Bootstrap.class);

    private ClassPathXmlApplicationContext context;

    /**
     * Start the service
     * @throws Exception
     */
    @Override
    protected void startUp() throws Exception {
        context = new ClassPathXmlApplicationContext(new String[]{"classpath:spring/applicationContext-service-async.xml"});
        context.start();
        context.registerShutdownHook();
        LOG.info("sgpay-web started successfully!");
    }

    /**
     * Stop the service
     * @throws Exception
     */
    @Override
    protected void shutDown() throws Exception {
        context.stop();
        LOG.info("sgpay-web stopped successfully!");
    }
}

